package com.lintesis.lintesisview.common.converters;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.zkoss.zk.ui.Component;
import org.zkoss.zkplus.databind.TypeConverter;

public class MonthFormatConverter implements TypeConverter
{
	SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");

	@Override
	public Object coerceToBean(Object arg0, Component comp)
	{
		if (arg0 == null)
		{
			return null;
		}
		try
		{
			return sdf.parseObject(String.valueOf(arg0));
		} catch (ParseException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Object coerceToUi(Object arg0, Component comp)
	{
		if (arg0 == null || String.valueOf(arg0).length() == 0)
		{
			return null;
		}
		return sdf.format(arg0);
	}
}
